package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.learning.domain.dto.LearningPlanDTO;
import com.tianji.learning.domain.vo.LearningLessonVO;
import com.tianji.learning.domain.vo.LearningPlanPageVO;
import com.tianji.learning.domain.vo.LearningPlanVO;
import com.tianji.learning.service.ILearningLessonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 学生课程表 前端控制器
 * </p>
 *
 * @author 陈彦祖
 * @since 2024-11-06
 */
@Api(tags = "我的课表接口")
@RestController
@RequestMapping("/lessons")
@RequiredArgsConstructor
public class LearningLessonController {

    private final ILearningLessonService learningLessonService;

    /**1
     * 分页查询我的课表
     * @param pageQuery
     * @return
     */
    @ApiOperation("分页查询我的课表")
    @GetMapping("/page")
    public PageDTO<LearningLessonVO> queryMyLessonPage(PageQuery pageQuery){
        return learningLessonService.queryMyLessonPage(pageQuery);
    }

    /**2
     * 查询正在学习的课程
     */
    @ApiOperation("查询正在学习的课程")
    @GetMapping("/now")
    public LearningLessonVO queryNowLearning(){
        return learningLessonService.queryNowLearning();
    }

    /**3
     * 删除课表中课程
     */
    @ApiOperation("删除课表中课程")
    @DeleteMapping("/{courseId}")
    public void deleteLesson(@PathVariable("courseId") Long courseId){
        learningLessonService.deleteLesson(null,courseId);
    }

    /**4
     * 检查课程是否有效
     */
    @ApiOperation("检查课程是否有效")
    @GetMapping("/{courseId}/valid")
    public Long checkCourseValid(@PathVariable("courseId") Long courseId){
        return learningLessonService.checkCourseValid(courseId);
    }

    /**5
     * 查询指定课程的学习记录
     */
    @ApiOperation("查询指定课程的学习记录")
    @GetMapping("/{courseId}")
    public LearningLessonVO queryLesson(@PathVariable("courseId") Long courseId){
        return learningLessonService.queryLesson(courseId);
    }

    /**6
     * 统计课程学习人数
     */
    @ApiOperation("统计课程学习人数")
    @GetMapping("/{courseId}/count")
    public Integer countStudent(@PathVariable("courseId") Long courseId){
        return learningLessonService.countStudent(courseId);
    }

    /**7
     * 创建修改学习计划
     */
    @ApiOperation("创建修改学习计划")
    @PostMapping("/plan")
    public void createPlans(@Valid @RequestBody LearningPlanDTO planDTO) {
        learningLessonService.createPlans(planDTO);
    }

    /**
     * 查询我的学习计划
     */
    @ApiOperation("查询我的学习计划")
    @GetMapping("/plans")
    public LearningPlanPageVO queryMyPlan(PageQuery pageQuery){
        return learningLessonService.queryMyPlan(pageQuery);
    }
}
